<?php
class rooms extends ujn_controller {
	var $main_url = '';
	var $login_url = '';
	
	function _before() {
		$this->main_url = ujn::getCFG('plat.url.main_url');
		$this->login_url = ujn::getCFG('plat.url.login_url');
	}
	
	public function lists() {
		$params = array( 'p' => 'facebook' );
		$url = $this->main_url . '_hookdoor/_datadoor.php?rooms-lists';
		$x = tls_func::rest_request('POST', $url, null, $params, false, true);
		
		$items = $x['data']['flag'] ? $x['data']['lists'] : array(); 
		$this->assign(array(
			'items'	=> $items,
		));
	}
	
	public function add() {
		if( isset( $_POST['form_id'] ) ) {
			$params = $_POST;
			$params['p'] = 'facebook';
			$params['flag'] = 0; //添加
			$url = $this->main_url . '_hookdoor/_datadoor.php?rooms-edit';
			$x = tls_func::rest_request('POST', $url, null, $params, false, true);
			
			if( $x['data']['flag'] ) {
				$this->redirect('?rooms-lists');
			}
			else{
				echo '添加失败!';exit;
			}
		}
	}
	
	public function edit(){
		$tid = (isset($_REQUEST['tid']) && !empty($_REQUEST['tid'])) ? $_REQUEST['tid'] : '0';
		
		if( isset( $_POST['form_id'] ) ) {
			$params = $_POST;
			$params['p'] = 'facebook';
			$url = $this->main_url . '_hookdoor/_datadoor.php?rooms-edit';
			$x = tls_func::rest_request('POST', $url, null, $params, false, true);
			
			if( $x['data']['flag'] ) {
				$this->redirect('?rooms-lists');
			}
			else{
				echo '修改失败!';exit;
			}
		}
		
		if( !empty($tid) ){
			$params = array( 'p' => 'facebook', 'tid' => $tid );
			$url = $this->main_url . '_hookdoor/_datadoor.php?rooms-get';
			$x = tls_func::rest_request('POST', $url, null, $params, false, true);
			$item = $x['data']['lists'];
			$this->assign(array(
				'item'	=> $item,
			));
		}
	}
}